﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Utils;

namespace COFE.Core
{
    /// <summary>
    /// Used by Web Services, user can access the property as resource (e.g. \contents\{id}\resourceName)
    /// </summary>
    public class ResourceAttribute : Attribute
    {
        private string _resourceName = null;

        /// <summary>
        /// The resource is available as the specified type when in web services, conversion may be required.
        /// </summary>
        public MediaType MediaType { get; private set; }

        public bool MajorProperty { get; private set; }

        public ResourceAttribute(MediaType mediaType, bool majorProperty = true)
        {
            MediaType = mediaType;
            MajorProperty = majorProperty;
        }
    }

    /// <summary>
    /// Extends ResourceAttribute.
    /// </summary>
    public static class ResourceExtension
    {
        /// <summary>
        /// Returns whether a property is resource.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <returns></returns>
        public static bool IsResource<T>(T item)
        {
            return EnumAttributeUtils<ResourceAttribute, T>.FindAttribute(item) != null;
        }

      

    }
}
